{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>购药界面</title>
    <!-- 引入 layui.css -->
    <link href="{%static '/css/layui.css'%}" rel="stylesheet">
</head>
<body>
<!--处方工具栏-->
<script id="btnaddchufang"  type="text/html">
    <div class="layui-btn-group">
        <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" lay-event="zibianchufang">自编处方</button>
        <button type="button" class="layui-btn layui-btn-sm layui-btn-primary" lay-event="zhuanyechufang">专业处方</button>
    </div>
</script>
<script id="chufangBar" type="text/html">
    <button type="button" class="layui-btn layui-btn-sm" id="assignbtn" lay-event="assign_event">
        确定
    </button>
    <button type="button" class="layui-btn layui-btn-sm" id="cancel_btn" lay-event="cancel_event">
        取消
    </button>
</script>
<div class="layui-container">
    <table class="layui-table" style="height:full-150" id="infoTable"></table>
</div>


<script src="{%static '/js/layui.min.js'%}" charset="utf-8"></script>
<script>
    layui.use(['layer','jquery','table'], function () {
        var $ = layui.jquery,
            layer = layui.layer,
            table = layui.table;
        table.render({
           elem:"#infoTable",
           url:"/api/prescription/prescription/?user_id={{user_id}}",
           height:'full-135',
           toolbar: '#btnaddchufang',
           page:true,
           cols:[[
               {toolbar:'#chufangBar',title:"操作",width:150,fixed:'left'},
               {title:"序号",type:"numbers"},
               {field:'OrderNum',title:"处方编号",minwidth:150},
               {field:'OrderType',title:"处方类型",minwidth:100,templet:function(data){
                   if (data.OrderType=="1"){
                       return "专业处方"
                   }else{
                       return "自编处方"
                   }
               }},
               {field:'OrderDt',title:"药方发药日期",minwidth:180},
               {field:'OrderDtm',title:"药方发药具体时间",minwidth:180},
               {field:'OrderStatus',title:"状态",width:100,templet:function(data){
                   if (data.OrderStatus=="1"){
                       return "已选中"
                   }else{
                       return "未选中"
                   }
               }},

           ]],
           even:true,     //开启隔行背景
           request:{
               "pageName":"pageNum",
               "limitName":"pageSize"
           },
           parseData:function(res){
               d = {
                   "code":0,
                   "count":res.data.count,
                   "data":res.data.results
               }
               return d
           }
       });
<!--       工具栏-->
       table.on('tool(infoTable)',function(obj){
           if(obj.event == 'assign_event'){
               url = "/api/prescription/prescription/"+obj.data.id+"/"
               $.ajax({
                   url:url,
                   type:'put',
                   data:"is_active"+"=1&_method=put",
                   dataType:"json",
                   success:function(res){
                       if(res.code==200){
                           layer.msg(res.msg,{time:2*1000},function(){
                               table.reload('infoTable',function(){
                                   page:{curr:1}
                               });
                           });
                       }
                       else{
                           layer.msg(res.msg,{time:2*1000});
                       }
                   }
               })
           }
           else if(obj.event == 'cancel_event'){
               data = obj.data;
               url = "/api/prescription/prescription/"+data.id+"/"
               $.ajax({
                   url:url,
                   type:'put',
                   data:"is_active"+"=0&_method=put",
                   dataType:"json",
                   success:function(res){
                       if(res.code==200){
                           layer.msg(res.msg,{time:2*1000},function(){
                               table.reload('infoTable',function(){
                                   page:{curr:1}
                               });
                           });
                       }
                       else{
                           layer.msg(res.msg,{time:2*1000});
                       }
                   }
               })
           }
       });
    });
</script>
</body>
</html>